﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using DflyingForum.Core.Framework.DflyingPortal;

namespace DflyingForum.Core.Framework
{
    /// <summary>
    /// QueryString解析类
    /// </summary>
    public class Query
    {
        public static string Request(string input)
        {
            return HttpContext.Current.Request.QueryString[input];
        }

        public static int Request(string input, int defValue = 0)
        {
            string valueStr = Request(input);
            int value;
            if (int.TryParse(valueStr, out value))
            {
                return value;
            }
            return defValue;
        }

        public static DateTime Request(string input, DateTime defValue)
        {
            string valueStr = Request(input);
            DateTime value;
            if (DateTime.TryParse(valueStr, out value))
            {
                return value;
            }
            return defValue;
        }

        public static DateTime GetSelect(string input)
        {
            string valueStr = Request(input);
            DateTime value;
            switch (input)
            {
                case "today":
                    value = DateTime.Now.Date; break;
                case "twodays":
                    value = DateTime.Now.Date.AddDays(-1); break;
                case "oneweek":
                    value = DateTime.Now.AddDays(-7); break;
                case "onemonth":
                    value = DateTime.Now.AddMonths(-1); break;
                case "threemonths":
                    value = DateTime.Now.AddMonths(-3); break;
                case "all":
                    value = DefaultValue.MinTime; break;
                default:
                    value = DefaultValue.MinTime; break;
            }
            return value;
        }
    }
}
